#include "List.h"


class Solution {
public:
    ListNode* removeNthFromEnd(ListNode* head, int n) {
        if (head == NULL) return NULL;
        ListNode* dummy = new ListNode(0);
        dummy->next = head;
        auto first = head, second = dummy;
        while (n--)
        {
            first = first->next;
        }
        while (first)
        {
            second = second->next; //此时second 所指向的 为删除节点的前一个节点
            first = first->next;
        }
        second->next = second->next->next;
        return dummy->next;
    }
};